import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '@/pages/Home';

Vue.use(VueRouter);

// 因为是同构应用 为了防止数据交叉请求带来的状态污染 跟创建Vue实例用函数导出是一个意思 需要用一个函数的方式导出router
export const createRouter = () => {
  const router = new VueRouter({
    mode: 'history',
    routes: [
      {
        path:'/',
        name: 'home',
        component: Home
      },
      {
        path: '/about',
        name: 'about',
        component: () => import('@/pages/About')
      },
      {
        path: '/posts',
        name: 'posts',
        component: () => import('@/pages/Posts')
      },
      {
        path: '*',
        name: 'error404',
        component: () => import('@/pages/404')
      }
    ]
  });
  return router;
}